package com.shop.cereshop.app.dl.logic.controller;

import com.shop.cereshop.app.dl.logic.service.DlBuyerUserService;
import com.shop.cereshop.app.dl.logic.utils.ResultInfo;
import com.shop.cereshop.app.dl.logic.vo.Statistics;
import com.shop.cereshop.app.page.after.AfterDetail;
import com.shop.cereshop.app.service.after.CereOrderAfterService;
import com.shop.cereshop.app.service.buyer.CereBuyerUserService;
import com.shop.cereshop.app.service.order.CereShopOrderService;
import com.shop.cereshop.commons.domain.buyer.CereBuyerUser;
import com.shop.cereshop.commons.utils.EmptyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: dlshop
 * 描述：
 * @author: 我好帅
 * @create: 2021-06-16 10:13
 **/
@RestController
@RequestMapping("/api")
@CrossOrigin
public class CereBuyerUserController {

    @Autowired
    private DlBuyerUserService buyerUserService;
    @Autowired
    private CereOrderAfterService cereOrderAfterService;
    @Autowired
    private CereBuyerUserService cereBuyerUserService;

    //获取转发新闻计数
    @PostMapping("/getForwardNewsCount")
    public ResultInfo getForwardNewsCount(HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        CereBuyerUser user = null;
        if (!EmptyUtils.isEmpty(token)) {
            //根据token查询用户信息
            user = cereBuyerUserService.findByToken(token);
        }
        //获取当前登录账户
//        CereBuyerUser user = (CereBuyerUser) request.getAttribute("user");
        if(user == null){
            return new ResultInfo(new Statistics());
        }
        return buyerUserService.getForwardNewsCount(user.getBuyerUserId());
    }
    //售后详情
    @PostMapping("/afterSaleDetails")
    public ResultInfo afterSaleDetails(Long afterId) throws Exception {
        AfterDetail byId = cereOrderAfterService.getById(afterId);
        return new ResultInfo(byId);
    }

}
